package com.prj.util;

import java.util.ArrayList;
import java.util.List;

import com.prj.entity.TM;
import com.prj.entity.XM;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HtmlUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;

public class TmUtil {
	
	public static String getTh(String str) {
		
		
		
    	String newChar = "";
		for(int i = 0; i < str.length(); i++) {
			char c = str.charAt(i);
			if(Character.isDigit(c)){
				newChar += c;
			} else {
				break;
			}
		}
		return newChar;
    }
    
   
    
    public static String getDa(String str) {
    	String newChar = "";
		for(int i = 0; i < str.length(); i++) {
			char c = str.charAt(i);
			if(Character.isUpperCase(c)){
				newChar += c;
			}
		}
		return newChar;
		
    }



	public static String getBM(String tkDl) {
		if(StrUtil.isNotBlank(tkDl)){
			String str = "";
			if(tkDl.contains("基础")){
				str += "J";
			}
			if(tkDl.contains("专业")){
				str += "Z";
			}
			String no = tkDl.substring(14, tkDl.length()-1)
					          .replace("一", "1")
					          .replace("二", "2")
					          .replace("三", "3")
					          .replace("四", "4")
					          .replace("五", "5")
					          .replace("六", "6")
					          .replace("七", "7")
					          .replace("八", "8")
					          .replace("九", "9")
					          .replace("十", "10");
			return str += no;
		}
		return null;
	}
	
	public static JSONArray converTMList(List<TM> tmList) {
		JSONArray root = new JSONArray();
		for(TM tm : tmList) {
			root.add(convertTM(tm));
		}
		return root;
	}
	
	
	private static JSONObject convertTM(TM tm) {
		JSONObject root = new JSONObject();
		root.set("type", tm.getTkType() == 1 ? "single" : "multiple");
		root.set("question", HtmlUtil.escape(tm.getTkTitle()));
		
		JSONObject xm = new JSONObject();
		List<String> answer = new ArrayList<String>();
		
		for(int i = 0; i < tm.getXmList().size(); i++) {
			String xmNo = String.valueOf((char)('A'+i));
			XM x = tm.getXmList().get(i);
			xm.set(xmNo, HtmlUtil.escape(x.getXmTitle()));
			if(x.getDaFlag()==1) {
				answer.add(xmNo);
			}
		}
		if(tm.getTkType() == 1) {
			root.set("answer", answer.get(0));
		} else {
			root.set("answer", answer);
		}
		root.set("explanation", HtmlUtil.escape(tm.getTkContent()));
		root.set("options", xm);
		root.set("tkId", tm.getTkId());
		root.set("favFlag", tm.getFavFlag());
		return root;
	}



	public static void main(String[] args) {
		String camelCase = StrUtil.toCamelCase("Aba_Cdds_Fs");
		System.out.println(camelCase);
	}

}
